package com.invoicing.entity;
import com.invoicing.Service.CommodityService;
import com.invoicing.Service.OrderService;
import com.invoicing.Service.TypeService;
import com.invoicing.Service.VendService;
import javafx.beans.property.SimpleStringProperty;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class CommodityData {
    @Autowired
    private TypeService typeService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private VendService vendService;


    private final int id;
    private final int num;
    private final String name;
    private final String type;
    private int stock;
    private final int alert;
    private final float price;
    private  float discount;
    private final float vend_price;
    private final int vend_count;
    private final float sell_price;
    private int sell_count;
    private float sell_total;
    private final float vend_total;
    private String profit;
    //private final String orderDate;
    //private final String vendDate;
    //java.text.DecimalFormat   df   =new   java.text.DecimalFormat("#.00");
    DecimalFormat df2 = new DecimalFormat(".00");
    public CommodityData(Commodity commodity,int num,String type,float vend_price,int vend_count,float sell_price,int sell_count){

        this.id = commodity.getId();
        this.name = commodity.getName();



        this.num = num;//序号
        this.type  = type;
        this.vend_count = vend_count;
        this.vend_price = vend_price;

        this.sell_count = sell_count;
        this.stock = commodity.getStock();
        this.alert = commodity.getAlert();
        this.price = commodity.getPrice();
        this.sell_price = Float.parseFloat(df2.format(sell_price));
        this.discount = commodity.getDiscount();

        this.sell_total = Float.parseFloat(df2.format(this.sell_count*this.sell_price));
        this.vend_total = this.vend_count*this.vend_price;
        if(this.sell_price >=this.vend_price){
            if(this.sell_price-this.vend_price<1){
                this.profit = ("0"+df2.format(this.sell_price - this.vend_price))+"";
            }
            else {
                this.profit = (df2.format(this.sell_price - this.vend_price))+"";
            }
        }
        else{
            if(this.vend_price-this.sell_price<1){
                this.profit = ("-0"+df2.format(this.vend_price - this.sell_price));
            }
            else{
                this.profit = "-"+(df2.format(this.vend_price - this.sell_price))+"";
            }
        }//利润

    }
    public String getName(){
        return this.name;
    }
    public String getType(){
        return this.type;
    }
    public int getStock() {
        return stock;
    }
    public int getAlert() {
        return alert;
    }
    public float getPrice() {
        return price;
    }
    public float getDiscount() {
        return discount;
    }
    public float getVend_price() {
        return vend_price;
    }
    public int getVend_count() {
        return vend_count;
    }
    public int getSell_count() {
        return sell_count;
    }
    public float getSell_price(){ return this.sell_price;}

    public float getSell_total() {
        return sell_total;
    }

    public float getVendtotal() {
        return vend_total;
    }
    public int getNum(){return this.num;}
    public int getId(){return this.id;}
    public void setStock(int stock){this.stock = stock;}
    public void setSell_total(float total){this.sell_total = total;}
    public void setSell_count(int sell_count){this.sell_count = sell_count;}
    public String getProfit(){return this.profit;}
    public void setDiscount(float discount){this.discount = discount;}
}
